const api = "api"
const askForLeave = api + "/ask-for-leave"
const course = api + "/course"
const clazz = api + "/clazz"
const user = api + "/user"
const userCourse = api + "/user-course"
const signTask = api + "/sign-task"
const privateChatMsg = api + "/private-chat-msg"
const groupChatMsg= api + "/group-chat-msg";
const notifyMsg = api + "/notify-msg"
const signIn = api + "/sign-in"
const dataFile = api + "/data-file"
const exerciseTitle = api + "/exercise-title"
const exercise = api + "/exercise"
const userAnswer = api + '/user-answer';
const fraction = api + "/fraction";
const collect = api + "/collect";
const swiper = api + "/swiper";


const httpApi = (Vue, vm) => {


	// 注册相关api
	let senderEmailCode = (email) => vm.$u.get(api + "/sender/" + email)
	let validateEmail = (email, code) => vm.$u.get(api + "/validate/" + email + "/" + code)
	let register = (data) => vm.$u.post(api + "/register", data);


	// 登录相关api
	let login = (data) => vm.$u.post(api + "/login", data);
	let getInfo = () => vm.$u.get(api + '/info');
	let logout = () => vm.$u.get(api + '/logout');
	let getCodeImg = () => vm.$u.get(api + '/captcha_image');


	//请假相关api
	let getAskForLeaveById = (pageNum, userId) => vm.$u.get(askForLeave + '/get/' + pageNum + "/" + userId);
	let getAskForLeaveByClazzId = (pageNum, clazzId) => vm.$u.get(askForLeave + '/audit/' + pageNum + "/" + clazzId);
	let saveAskForLeave = (data) => vm.$u.post(askForLeave + "/save", data);
	let getAskForLeaveDetailById = (id, audit) => vm.$u.get(askForLeave + '/get/' + id + "?audit=" + audit);
	let updateAskForLeave = (data) => vm.$u.put(askForLeave + "/update", data);
	let getNotLeaveOffByUserId = (userId) => vm.$u.get(askForLeave + "/leave-off/" + userId);

	//课程相关api
	let getMyTeachCourse = (pageNum, userId) => vm.$u.get(course + '/get/teach/' + pageNum + "/" + userId);
	let getMyAttendCourse = (pageNum, userId) => vm.$u.get(course + '/get/attend/' + pageNum + "/" + userId);
	let createCourse = (data) => vm.$u.post(course + "/save", data);
	let getCourseById = (id) => vm.$u.get(course + "/get/" + id);
	let getCourseByInvestCode = (investCode) => vm.$u.get(course + "/get/invest/" + investCode);
	let getUserByCourseId = (courseId) => vm.$u.get(course + "/create/user/" + courseId);
	let deleteCourse = (courseId) => vm.$u.delete(course + "/delete/" + courseId);

	// 班级相关api
	let createClazz = (data) => vm.$u.post(clazz + "/save", data);
	let getClazzById = (id) => vm.$u.get(clazz + "/get/" + id);
	let getClazzVoById = (id) => vm.$u.get(clazz + "/clazz/" + id);
	let getClazzByUserId = (id) => vm.$u.get(clazz + "/user/" + id);
	let getClazzByInvestCode = (investCode) => vm.$u.get(clazz + "/invest/" + investCode);
	let getUserByClazzId = (clazzId) => vm.$u.get(clazz + "/create/user/" + clazzId);
	let deleteClazz = (clazzId) => vm.$u.delete(clazz + "/delete/" + clazzId);

	// 资料相关api
	let getDataFilePage = (courseId, pageNum) => vm.$u.get(dataFile + "/" + courseId + "/" + pageNum);
	let getDataFile = (id) => vm.$u.get(dataFile + "/get/" + id);

	// 用户相关api
	let getUserOne = (email) => vm.$u.get(user + "/get/" + email)
	let getChatUser = (pageNum, userId) => vm.$u.get(user + "/get/chat-user/" + pageNum + "/" + userId);
	let getChatUserByName = (name) => vm.$u.get(user + "/user/" + name);
	let updateUser = (data) => vm.$u.put(user + "/update", data);
	let addFriend = (data) => vm.$u.post(user + "/add-friend", data);
	let deleteFriend = (data) => vm.$u.post(user + "/delete-friend", data);
	let joinClazz = (userId, clazzId) => vm.$u.put(user + "/join/" + userId + "/" + clazzId);
	let getStudentByClazzId = (pageNum, clazzId) => vm.$u.get(user + "/get/student/" + pageNum + "/" + clazzId);
	let changePwd = (data) => vm.$u.put(user + "/change/pwd", data);
	let forgetPwd = (data) => vm.$u.put(user + "/forget/pwd", data);
	let exitClazz = (userId,clazzId) => vm.$u.put(user + "/exit/" + userId + "/" + clazzId);

	// 用户课程相关api
	let joinCourse = (data) => vm.$u.post(userCourse + "/join", data)
	let getCourseUser = (courseId, pageNum) => vm.$u.get(userCourse + "/" + pageNum + "/" + courseId);
	let kickOut = (userId, courseId) => vm.$u.delete(userCourse + "/delete/" + userId + "/" + courseId);

	// 签到任务相关api
	let postSignTask = (data) => vm.$u.post(signTask + "/save", data);
	let getSignTaskByCourseId = (pageNum, courseId) => vm.$u.get(signTask + "/get/" + pageNum + "/" + courseId);
	let getSignStatusList = (courseId, pageNum, userId) => vm.$u.get(signTask + "/s/" + courseId + "/" + pageNum + "/" + userId);

	// 私聊消息相关api
	let queryChatMsg = (pageNum, data) => vm.$u.get(privateChatMsg + "/get/" + pageNum, data);
	let queryUnsignedMsg = (receiverId) => vm.$u.get(privateChatMsg + "/get/unsigned/" + receiverId);

	// 群聊消息相关api
	let queryGroupMsg = (pageNum, data) => vm.$u.get(groupChatMsg + "/get/" + pageNum, data);

	// 通知消息相关api
	let queryNotifyMsg = (pageNum, userId) => vm.$u.get(notifyMsg + "/get/" + pageNum + "/" + userId);
	let updateNotifyMsgUser = (data) => vm.$u.post(notifyMsg + "/update", data);


	// 签到相关api
	let saveSignIn = (data) => vm.$u.post(signIn + "/save", data);
	let getSignDetail = (courseId, signTaskId, bt) => vm.$u.get(signIn + "/" + courseId + "/" + signTaskId + "/" + bt);

	// 上传base64的图片
	let uploadBase64Data = (data) => vm.$u.post(api + "/base64Upload", data);


	// 习题标题相关api
	let saveExerciseTitle = (data) => vm.$u.post(exerciseTitle + "/save", data);
	let getExerciseTitle = (pageNum, id) => vm.$u.get(exerciseTitle + "/" + pageNum + "/" + id);
	let getStuExerciseTitle = (pageNum, id) => vm.$u.get(exerciseTitle + "/stu/" + pageNum + "/" + id);

	// 习题相关api
	let saveExercise = (data) => vm.$u.post(exercise + "/save", data);
	let getExercise = (pageNum, id) => vm.$u.get(exercise + "/" + pageNum + "/" + id);
	let getAnswerExercise = (pageNum, id, userId) => vm.$u.get(exercise + "/answer/" + pageNum + "/" + id + "/" + userId);
	let getTeaExercise = (pageNum, id) => vm.$u.get(exercise + "/tea/" + pageNum + "/" + id);
	let updateExercise = (data) => vm.$u.put(exercise + "/update", data);
	let removeExercise = (id) => vm.$u.delete(exercise + "/delete/" + id);

	// 用户答案api
	let saveUserAnswer = (id, data) => vm.$u.post(userAnswer + "/save/" + id, data);

	// 学生分数
	let getFraction = (pageNum, id) => vm.$u.get(fraction + "/" + pageNum + "/" + id);

	//收藏相关api
	let getCollect = (pageNum, id) => vm.$u.get(collect + "/" + pageNum + "/" + id);
	let saveCollect = (data) => vm.$u.post(collect + "/save", data);
	let removeCollect = (id) => vm.$u.delete(collect + "/delete/" + id);

	//轮播图相关api
	let getSwiper = () => vm.$u.get(swiper + "/get");

	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		senderEmailCode,
		register,
		validateEmail,

		login,
		getInfo,
		logout,
		getCodeImg,

		saveAskForLeave,
		getAskForLeaveById,
		getAskForLeaveDetailById,
		getAskForLeaveByClazzId,
		updateAskForLeave,
		getNotLeaveOffByUserId,

		getMyTeachCourse,
		getMyAttendCourse,
		createCourse,
		getCourseById,
		getCourseByInvestCode,
		getUserByCourseId,
		deleteCourse,

		createClazz,
		getClazzById,
		getClazzByInvestCode,
		getClazzByUserId,
		getClazzVoById,
		getUserByClazzId,
		deleteClazz,

		getDataFile,
		getDataFilePage,

		getUserOne,
		getChatUser,
		updateUser,
		addFriend,
		deleteFriend,
		joinClazz,
		getStudentByClazzId,
		getChatUserByName,
		changePwd,
		forgetPwd,
		exitClazz,

		joinCourse,
		getCourseUser,
		kickOut,

		postSignTask,
		getSignTaskByCourseId,
		getSignStatusList,

		queryChatMsg,
		queryUnsignedMsg,
		queryGroupMsg,

		queryNotifyMsg,
		updateNotifyMsgUser,

		saveSignIn,
		getSignDetail,

		uploadBase64Data,

		saveExerciseTitle,
		getExerciseTitle,
		getStuExerciseTitle,

		saveExercise,
		getExercise,
		getTeaExercise,
		updateExercise,
		removeExercise,

		getAnswerExercise,
		saveUserAnswer,

		getFraction,

		getCollect,
		saveCollect,
		removeCollect,

		getSwiper
	};
}

export default httpApi

